package 矩阵.矩阵特殊点;

/**
 * TODO
 *
 * @className: jztsd
 * @description: TODO
 * @author: 等什么柠檬君
 * @date: 2022-04-29 11:11
 **/
public class jztsd {
    // 0 0 0 0 0
    // 1 0 0 0 0
    // 0 1 0 0 0
    // 0 0 1 0 0
    // 0 0 0 1 1
//    [[0,0,0,0,0],[1,0,0,0,0],[0,1,0,0,0],[0,0,0,1,0],[0,0,0,1,1]]
//    [[1,0,0],[0,0,1],[1,0,0]]

//    10000
//    01000
//

//    1 0 0
//    0 0 1
//    1 0 0
    public static void main(String[] args) {
//        int [][] arr = {{0,0,0,0,0},{1,0,0,0,0},{0,1,0,0,0},{0,0,1,0,0},{0,0,0,1,1}};
//        int [][] arr = {{1,0,0},{0,0,1},{1,0,0}};
//        int [][] arr = {{1,0,0},{0,1,0},{0,0,1}};
        int [][] arr = {{0,0},{0,0},{1,1}};
        System.out.println(numSpecial(arr));

    }
    public static int numSpecial(int[][] mat) {
        int[] rowCount = new int[mat.length];       //1
        int[] colCount = new int[mat[0].length];
        for(int i = 0;i < mat.length;i++){
            for(int j = 0;j < mat[0].length;j++){
                if(mat[i][j] == 1){                 //2
                    rowCount[i] ++;
                    colCount[j] ++;
                }
            }
        }
        int count = 0;
        for(int i = 0;i < mat.length;i++){
            for(int j = 0;j < mat[0].length;j++){
                if(mat[i][j] == 1 && rowCount[i] == 1 && colCount[j] == 1) {
                    count++;//3
                }
            }
        }
        return count;
    }

//    public static int numSpecial(int[][] mat) {
////        String arrX[] = new String[mat[0].length];
////
////        String arrY[] = new String[mat[0].length];
//        ArrayList<String> arrX = new ArrayList<>();
//        ArrayList<String> arrY = new ArrayList<>();
//        int count = 0;
//        for(int i = 0;i < mat.length;++i){
//            String x = "";
//            String y = "";
//            String result = "";
////            System.out.println(Arrays.toString(mat[i]).replace(",","").replace("[","").replace("]",""));
////
////            for(int j = 0;j < mat[i].length;++j){
////                result+=mat[j][i]+" ";
////            }
////            System.out.println(result);
//
//            for(int j = 0;j < mat[i].length;++j){
////                System.out.println("行"+i+" 列"+j+" 值"+mat[i][j]);
////                if(mat[i][j] == 1){
////                    arr[i] += mat[i][j];
////
////                }
////
////                if(mat[j][i] == 1){
////                    arr2[i] += mat[j][i];
////
////                }
////                System.out.println(Arrays.toString(mat[i]));
//                x += mat[i][j];
//                y += mat[j][i];
//
//            }
//            arrX.add(x);
//            arrY.add(y);
////            System.out.println("第"+i+"行 x "+x+"->"+Integer.valueOf(x, 2));
//
//
////            System.out.println("第"+i+"行 y "+y+"->"+Integer.valueOf(y, 2));
////            System.out.println("第"+i+"行  "+x+y);
//
//
//
////            System.out.println("整合 "+Integer.valueOf(x+y, 2).intValue());
//
//
//        }
//
////
////        System.out.println(Arrays.toString(arrX));
////        System.out.println(Arrays.toString(arrY));
//        for (int i = 0; i < mat.length; i++) {
//           for (int j = 0; j < mat[i].length; j++) {
//                if (mat[i][j]==1){
//                    System.out.println("第"+i+"行 第"+j+"个字符 所在行->"+arrX.get(i));
//                    System.out.println("匹配"+j+"列字符 所在列->"+arrY.get(j));
////                    System.out.println("第"+i+"行 第"+j+"个字符 所在行->"+arrX[i].substring(j+1));
////                    System.out.println(arrX[i]+arrY[j]);
////                    System.out.println("匹配"+((Integer.valueOf(arrX[i], 2) & (Integer.valueOf(arrY[j], 2)))==0));
//
//                    if ((arrX.get(i)+arrY.get(j)).replace("0","").length()-1==1){
//                        ++count;
//                    }
////                    System.out.println("------->"+   (((Integer.valueOf(arrX[i], 2) & (Integer.valueOf(arrY[j], 2))) & ((Integer.valueOf(arrX[i], 2) & (Integer.valueOf(arrY[j], 2)) )- 1))==0));
////                if ((((Integer.valueOf(arrX[i], 2) & (Integer.valueOf(arrY[j], 2))) & ((Integer.valueOf(arrX[i], 2) & (Integer.valueOf(arrY[j], 2)) )- 1))==0)){
////                    ++count;
////                 }
//                }
//
//
//            }
//        }
////        int result = 0;
////        for(int k = 0; k < arr.length; ++k){
////            if(arr[k]==1){
////                ++result;
////            }
////        }
////        System.out.println(Arrays.toString(arr));
////        System.out.println(Arrays.toString(arr2));
//        return count;
//    }
    public static int countChar(String a){
        System.out.println("截取-》"+a);
        return a.replace("0","").length()-1;
    }
}
